package com.chuck.learning.solutions;

public class 数组中找相同的元素 {

    //重点是  arr[3]
    public static void main(String[] args) {
        int arr[]={0,3,3,4,2,4};
        for (int i = 0; i < arr.length; i++) {
            while (arr[i] != i) {
                if (arr[i] == arr[arr[i]]) {
                   System.out.println(arr[i]);
                   break;
                }
                swap(arr, i, arr[i]);
            }
        }

    }

    public static void  swap(int nums[],int i,int j){
        int t =nums[i];
        nums[i]=nums[j];
        nums[j]=t;
    }

}
